home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / By the Book / Mac C Primer V1 CW9 / 68K and PPC Projects (CW9) / 4.3 - EventTrigger / EventTrigger.c < prev   
C/C++ Source or Header  |  1996-05-28  |  2KB  |  109 lines

  1. /********************************************************/
  2. /*                                                        */
  3. /*  EventTrigger Code from Chapter Four of                 */
  4. /*                                                        */
  5. /*    ** The Macintosh C Programming Primer, 2nd Ed. **    */
  6. /*                                                      */
  7. /*    Copyright 1992, Dave Mark and Cartwright Reed       */
  8. /*                                                        */
  9. /*  This program demonstrates specific Mac programming    */
  10. /*    techniques.                                            */
  11. /*                                                        */
  12. /********************************************************/
  13.  
  14. /* Note that the isHighLevelEventAware flag is set in the
  15.    Project preferences panel (in the SIZE popup) in
  16.    BOTH EventTracker and in EventTrigger. If you don't do this,
  17.    EventTrigger won't be able to send the Apple events
  18.    and EventTracker won't be able to receive them!!!
  19.    Also, be sure the Application Creator is set to
  20.    'Prmr' in EventTracker so EventTrigger can
  21.    find it. - Dave
  22. */
  23.  
  24. #include <AppleEvents.h>
  25. #include <GestaltEqu.h>
  26.  
  27. #define kGestaltMask    1L
  28.  
  29. /***************/
  30. /*  Functions  */
  31. /***************/
  32.  
  33. void    ToolBoxInit( void );
  34. void    EventsInit( void );
  35. void    SendEvent( AEEventID theAEEventID );
  36.  
  37.  
  38. /******************************** main *********/
  39.  
  40. void    main( void )
  41. {
  42.     ToolBoxInit();
  43.     EventsInit();
  44.     
  45.     SendEvent( kAEOpenApplication );
  46.     SendEvent( kAEOpenDocuments );
  47.     SendEvent( kAEPrintDocuments );
  48.     SendEvent( kAEQuitApplication );
  49. }
  50.  
  51.  
  52. /*********************************** ToolBoxInit */
  53.  
  54. void    ToolBoxInit( void )
  55. {
  56.     InitGraf( &qd.thePort );
  57.     InitFonts();
  58.     InitWindows();
  59.     InitMenus();
  60.     TEInit();
  61.     InitDialogs( 0L );
  62.     InitCursor();
  63. }
  64.  
  65.  
  66. /*********************************** EventsInit */
  67.  
  68. void    EventsInit( void )
  69. {
  70.     long    feature;
  71.     OSErr    err;
  72.     
  73.     err = Gestalt( gestaltAppleEventsAttr, &feature );
  74.     
  75.     if ( err != noErr )
  76.     {
  77.         SysBeep( 10 );    /*  Error calling Gestalt!!!  */
  78.         ExitToShell();
  79.     }
  80.     
  81.     if ( !( feature & ( kGestaltMask << gestaltAppleEventsPresent ) ) )
  82.     {
  83.         SysBeep( 10 );    /*  AppleEvents not supported!!!  */
  84.         ExitToShell();
  85.     }
  86.     
  87. }
  88.  
  89.  
  90. /******************************** SendEvent *********/
  91.  
  92. void    SendEvent( AEEventID theAEEventID )
  93. {
  94.     OSErr            err;
  95.     AEAddressDesc    address;
  96.     OSType            appSig;
  97.     AppleEvent        appleEvent, reply;
  98.     
  99.     appSig = 'Prmr';
  100.     
  101.     err = AECreateDesc( typeApplSignature, (Ptr)(&appSig),
  102.                 (Size)sizeof( appSig ), &address );
  103.     
  104.     err = AECreateAppleEvent( kCoreEventClass, theAEEventID, &address,
  105.             kAutoGenerateReturnID, 1L, &appleEvent );
  106.             
  107.     err = AESend( &appleEvent, &reply, kAENoReply + kAECanInteract,
  108.             kAENormalPriority, kAEDefaultTimeout, nil, nil );
  109. }